#ifndef _AUTO_LOCK_H_
#define _AUTO_LOCK_H_

#include "CritSection.h"

class CAutoLock
{
	CAutoLock (const CAutoLock&);
	const CAutoLock &operator = (const CAutoLock&);

public:
#ifndef _LOCK_DEBUG
	CAutoLock(ICritSection& cs);
#else
	CAutoLock(ICritSection& cs, const char* strFilePath, DWORD dwFileLine);
#endif
	~CAutoLock();

protected:
	ICritSection*	m_pCritSection;
#ifdef _LOCK_DEBUG
	LOCKINFO		m_lockinfo;
#endif
};


#ifdef _LOCK_DEBUG

#define AUTO_LOCK(_CS)			CAutoLock _lock(_CS, __FILE__, __LINE__)
#define AUTO_LOCK_DEFAULT()		CAutoLock _lock(*XObject::DefaultCriticalSection(), __FILE__, __LINE__)
#define CRIT_LOCK(_CS)			_CS.Lock(__FILE__, __LINE__)
#define CRIT_UNLOCK(_CS)		_CS.Unlock(__FILE__, __LINE__)

#else

#define AUTO_LOCK(_CS)			CAutoLock _lock(_CS)
#define AUTO_LOCK_DEFAULT()		CAutoLock _lock(*XObject::DefaultCriticalSection())
#define CRIT_LOCK(_CS)			_CS.Lock()
#define CRIT_UNLOCK(_CS)		_CS.Unlock()
#endif

#endif
